Framework

Contains information about a player's current game state.

Characters are a fundamental object type in Lilia. They are distinct from players, where players are the representation of a person's existence in the server that owns a character, and their character is their currently selected persona. All the characters that a player owns will be loaded into memory once they connect to the server. Characters are saved during a regular interval (lia.config.CharacterDataSaveInterval), and during specific events (e.g when the owning player switches away from one character to another).

They contain all information that is not persistent with the player; names, descriptions, model, currency, etc. For the most part, you'll want to keep all information stored on the character since it will probably be different or change if the player switches to another character. An easy way to do this is to use lia.char.registerVar to easily create accessor functions for variables that automatically save to the character object.

Functions

characterMeta:__eq(other)

Returns true if this character is equal to another character. Internally, this checks character IDs.

Parameters

  • other Character

    Character to compare to

Returns

  • any

    bool Whether or not this character is equal to the given character

Example Usage

print(lia.char.loaded[1] == lia.char.loaded[2])
 > false

characterMeta:__tostring()

Returns a string representation of this character

Returns

  • any

    string String representation

Example Usage

print(lia.char.loaded[1])
 > "character[1]"

characterMeta:ban(time)

Forces a player off their current character, and prevents them from using the character for the specified amount of time.

Parameters

  • time Float optional

    Amount of seconds to ban the character for. If left as nil, the character will be banned permanently

characterMeta:delete()

Deletes the character from the character database and removes it from memory.

characterMeta:destroy()

Destroys the character, removing it from memory and notifying clients to remove it.

characterMeta:getFlags()

Returns all of the flags this character has.

Returns

  • string

    Flags this character has represented as one string. You can access individual flags by iterating through the string letter by letter

characterMeta:getID()

Returns this character's database ID. This is guaranteed to be unique.

Returns

  • any

    number Unique ID of character

characterMeta:getItemWeapon()

Retrieves the character's equipped weapon and its corresponding item from the inventory.

Returns

  • any

    Entity|false The equipped weapon entity, or false if no weapon is equipped.

  • any

    Item|false The corresponding item from the character's inventory, or false if no corresponding item is found.

Example Usage

local weapon, item = character:getItemWeapon()

characterMeta:getPlayer()

Returns the player that owns this character.

Returns

  • any

    player Player that owns this character

characterMeta:giveFlags(flags)

Adds a flag to the list of this character's accessible flags. This does not overwrite existing flags.

Parameters

  • flags String

    Flag(s) this character should be given

Example Usage

character:GiveFlags("pet")
 gives p, e, and t flags to the character

See Also

characterMeta:giveMoney(amount, takingMoney)

Gives or takes money from the character's wallet.

Parameters

  • amount Integer

    The amount of money to give or take.

  • takingMoney Boolean default: false

    Whether the operation is to take money from the character.

Returns

  • any

    bool Whether the operation was successful.

characterMeta:hasFlags(flags)

Returns true if the character has the given flag(s).

Parameters

  • flags String

    Flag(s) to check access for

Returns

  • bool

    Whether or not this character has access to the given flag(s)

characterMeta:hasMoney(amount)

Checks if the character has at least the specified amount of money.

Parameters

  • amount Integer

    The amount of money to check for.

Returns

  • any

    bool Whether the character has at least the specified amount of money.

Example Usage

local hasEnoughMoney = character:hasMoney(100)

characterMeta:kick()

Forces a player off their current character, and sends them to the character menu to select a character.

characterMeta:save(callback)

Saves this character's info to the database.

Parameters

  • callback Function default: nil

    Function to call when the save has completed.

Example Usage

lia.char.loaded[1]:save(function()
	print("Done saving " .. lia.char.loaded[1] .. "!")
end)
> Done saving character[1]! -- after a moment

characterMeta:setFlags(flags)

Sets this character's accessible flags. Note that this method overwrites all flags instead of adding them.

Parameters

  • flags String

    Flag(s) this charater is allowed to have

See Also

characterMeta:sync(receiver)

Internal

This is an internal function! You are able to use it, but you risk unintended side effects if used incorrectly.

Networks this character's information to make the given player aware of this character's existence. If the receiver is not the owner of this character, it will only be sent a limited amount of data (as it does not need anything else). This is done automatically by the framework.

Parameters

  • receiver Player default: nil

    Player to send the information to. This will sync to all connected players if set to nil.

characterMeta:takeFlags(flags)

Removes this character's access to the given flags.

Parameters

  • flags String

    Flag(s) to remove from this character

Example Usage

-- for a character with "pet" flags
character:takeFlags("p")
-- character now has e, and t flags

characterMeta:takeMoney(amount)

Takes money from the character's wallet.

Parameters

  • amount Integer

    The amount of money to take.

Returns

  • any

    bool Whether the operation was successful.